//****************************************************************
//* Copyright (c) 2004 Ford Motor Company. All Rights Reserved.
//*
//* $$Workfile:   FindPermissonsByUsrQuery.java  $$
//* $$Revision:   1.3  $$
//* $$Author:   aponte  $$
//* $$Date:   Dec 15 2008 07:08:28  $$
//*
//*****************************************************************
package ar.com.ford.it.fullEconomics.persistence.dao.query;

import oracle.toplink.expressions.Expression;
import oracle.toplink.expressions.ExpressionBuilder;
import ar.com.ford.it.fullEconomics.persistence.dto.Tms0005AccprofVw;
import com.ford.it.persistence.impl.toplink.CustomExpressionFactory;

public class FindPermissonsByUsrQuery implements CustomExpressionFactory {

    
    public Expression createExpression(ExpressionBuilder builder,
                                       Object[] parameters) {
        Expression exp = null;
        Tms0005AccprofVw tms0005AccprofVw = (Tms0005AccprofVw) parameters[0];
        String plantCode = null;
        String profileCode = null;
        String systemCode = null;
        
        plantCode = tms0005AccprofVw.getMs0005PlantCodeC();
        systemCode = tms0005AccprofVw.getMs0005SystemCodeC();
        profileCode = tms0005AccprofVw.getMs0005ProfileCodeC();
        
        if (plantCode != null) {
            exp = builder.get("ms0005PlantCodeC").equal(plantCode);
        }
        
        if (profileCode != null) {
            if (exp != null)
                exp = exp.and(builder.get("ms0005ProfileCodeC").equal(profileCode));
            else
                exp = builder.get("ms0005ProfileCodeC").equal(profileCode);
        }
        
        if (systemCode != null) {
            if (exp != null)
                exp = exp.and(builder.get("ms0005SystemCodeC").equal(systemCode));
            else
                exp = builder.get("ms0005SystemCodeC").equal(systemCode);
        }

        return exp;
    }

}
